<app>
    <h3 class="title">{ opts.title } { sumscore }</h3>
    
      <div class="formfield">以下项目请(单)勾选，系统将自动计算总分；如果不知道怎么勾选，请致电13682650163询问）</div>
       <form onsubmit={ view1_submit } id="view1" style="display:{ views[0] ? 'block':'none' }">
       <ul>
            <li each={ datasource,di in onedatasources }>
                <h3>{ datasource.title }</h3>
                <div each={ data ,i in datasource.data }>
                    <p class="problem">{ data.title }<span class="require">*<span></p>
                    <div class="qestion">
                        <div each={ item ,j in data.items } class='radio-check'>
                            <input type='radio' value="{ item.score }" onclick={ toggle } name='view1-{ di }-{ i }' id='view1-{ di }-{ i }-{ j }'/>
                            <label for='view1-{ di }-{ i }-{ j }' class>{ item.desc }</label>
                        </div>
                    </div>
                </div>
            </li>
            <button class="button button-primary  button-rounded button-large">提交<buttom>
        </ul>
    </form>
     <form onsubmit={ add } id="view2" style="display:{ views[1] ? 'block':'none' }">
        <ul>
            <li each={ datasource,di in datasources }>
                <h3>{ datasource.title }</h3>
                <div each={ data ,i in datasource.data }>
                    <p class="problem">{ data.title }<span class="require">*<span></p>
                    <div class="qestion">
                        <div each={ item ,j in data.items } class='radio-check'>
                            <input type='radio' value="{ item.score }" onclick={ toggle } name='{ di }-{ i }' id='{ di }-{ i }-{ j }' required="required"/>
                            <label for='{ di }-{ i }-{ j }' class>{ item.desc }</label>
                        </div>
                    </div>
                </div>
            </li>
            <input type="submit" value="提交">
        </ul>
    </form>
 <script>
    self = this

    self.disabled = true

    self.views =[1,0,0]
    //一票否决题目
    self.onedatasources = opts.onedatasources
    //一票否决题目 答题情况
    self.onelist = {}

    //题目数组
    self.datasources = opts.datasources


    //总分数
    self.sumscore = 0
    //已答题目数组
    self.scores = {}

    
    onetoggle(e){
         self.onelist[e.target.name]=e.target.value
         self.update()
    }

    view1_submit(e){
        self.views = [0,1,0]
        self.update()
        document.body.scrollTop=0
    }
    toggle(e){
        //- console.log(e.target.value)
        //- console.log(e.target.name)
        self.scores[e.target.name]=e.target.value

        //计算总分
        var sum = 0
        for(score in self.scores){
            console.log(score)
            sum = sum + parseInt(self.scores[score])
        }
        self.sumscore = sum
        console.log(self.sumscore)
    }

    //- edit(e) {
    //-   this.text = e.target.value
    //- }

    add(e) {
        console.log(self.sumscore)
        console.log(self.scores)
        console.log(e)
    }
  </script>
    
</app>